package com.example.administrator.animator;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private Context mContext;

    private Button red1;
    private AnimationSet set;
    private ImageView refresh;
    private Button red3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext=this;
        red1 = (Button) findViewById(R.id.red1);
        red3 = (Button) findViewById(R.id.red3);
        refresh = (ImageView) findViewById(R.id.red2);

        init();



    }

    private void init() {
        red1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LuckeyDialog.Builder builder = new LuckeyDialog.Builder(mContext);//调用style中的Diaog

                builder.setName("系统");
                builder.setOpenButton("", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
//                        Intent intent = new Intent(mContext,Open.class);
//                        startActivity(intent);
                        dialog.dismiss();
                    }
                });

                builder.setCloseButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        dialog.dismiss();
                    }
                });


//                <span style="color:#ff0000;">
                        Dialog dialog = builder.create();

                Window dialogWindow = dialog.getWindow();
                dialogWindow.setDimAmount(0);
                //dialogWindow.closeAllPanels();

                WindowManager m = getWindowManager();
                Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
                WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
                //p.setColorMode(Color.argb(0,0,0,0,));
                p.height = (int) (d.getHeight() * 0.8); // 高度设置为屏幕的0.6
                p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65



                dialogWindow.setAttributes(p);
//</span>
                        dialog.show();
            }
        });
    }

    public void rotat(View view) {
        set = new AnimationSet( true);
        RotateAnimation rotat=new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        //ScaleAnimation scale=new ScaleAnimation(0, 1f, 0, 1f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        set.addAnimation(rotat);
        //set.addAnimation(scale);
        set.setDuration(2000);
        refresh.setAnimation(set);
        set.start();
    }
}
